﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;

namespace LiuLin.OQ2014.Extension
{
    public class Parameter
    {
        public Parameter(string id)
        {
            ParameterID = id;
        }

        public ObjectId _id;
        public string ParameterID;
        public double Value1;
        public double Value2;
        public double Value3;
        public double Value4;
        public double Value5;
        public double Value6;
        public double Value7;
        public double Value8;
        public double Value9;
        public double Value10;
    }

    public class ParameterHelper
    {
        public static bool SaveParameter(Parameter parameter)
        {
            MongoDBHelper.CreateCollection(Config.GetConnectionString(),Config.GetDataBaseName(),"Parameter");
            MongoDBHelper.Delete(Config.GetConnectionString(), Config.GetDataBaseName(), "Parameter",Query.EQ("ParameterID",parameter.ParameterID));
            var resualt = MongoDBHelper.InsertOne<Parameter>(Config.GetConnectionString(), Config.GetDataBaseName(), "Parameter",parameter);
            return (resualt.Ok);
        }

        public static Parameter GetParameter(string id)
        {
            return MongoDBHelper.GetOne<Parameter>(Config.GetConnectionString(), Config.GetDataBaseName(), "Parameter",Query.EQ("ParameterID", id));
        }
    }
}
